package com.tendory.rxlocation;

import com.amap.api.location.AMapLocationClientOption;
import com.baidu.location.LocationClientOption;

/**
 * 对百度和高德ClientOption的封装,使用时其中一个Option为null
 */
public class ClientOption {
    private boolean hightAccuracy = true;
    private boolean needAddress = true;
    private int interval = 500;
    private boolean cacheEnable = false;
    private boolean isHandleError = true;

    public void setHightAccuracy(boolean hightAccuracy) {
        this.hightAccuracy = hightAccuracy;
    }

    public void setNeedAddress(boolean needAddress) {
        this.needAddress = needAddress;
    }

    public void setInterval(int interval) {
        this.interval = interval;
    }

    public void setCacheEnable(boolean cacheEnable) {
        this.cacheEnable = cacheEnable;
    }

    public boolean isHandleError() {
        return isHandleError;
    }

    public void setHandleError(boolean handleError) {
        isHandleError = handleError;
    }

    public LocationClientOption getBaiduOption() {
        final LocationClientOption option = new LocationClientOption();
        option.setLocationMode(hightAccuracy ? LocationClientOption.LocationMode.Hight_Accuracy : LocationClientOption.LocationMode.Battery_Saving);
        option.setIsNeedAddress(needAddress);
        option.setNeedDeviceDirect(false);
        option.setLocationNotify(false);
        option.autoNotifyMaxInterval = interval;
        option.setIgnoreKillProcess(true);
        option.setIsNeedLocationDescribe(true);
        option.setIsNeedLocationPoiList(true);
        option.SetIgnoreCacheException(false);
        option.setIsNeedAltitude(false);
        option.disableCache(!cacheEnable);
//        option.setCoorType();
        return option;
    }


    public AMapLocationClientOption getAmapOption() {
        final AMapLocationClientOption option = new AMapLocationClientOption();
        /**
         * 设置定位场景，目前支持三种场景（签到、出行、运动，默认无场景）
         */
        option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.Sport);
        option.setLocationMode(hightAccuracy ? AMapLocationClientOption.AMapLocationMode.Hight_Accuracy : AMapLocationClientOption.AMapLocationMode.Battery_Saving);
        option.setGpsFirst(false);
        //单位是毫秒，默认30000毫秒，建议超时时间不要低于8000毫秒。
        option.setHttpTimeOut(30000);
        option.setInterval(interval);//设置定位间隔,单位毫秒,默认为2000ms，最低1000ms。
        option.setNeedAddress(needAddress);
        //设置是否允许模拟位置,默认为true，允许模拟位置
        option.setMockEnable(false);
        option.setOnceLocation(false);
        option.setOnceLocationLatest(false);
        AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);
        option.setSensorEnable(false);
        option.setWifiScan(true);
//        option.setLocationCacheEnable(true);
        option.setLocationCacheEnable(cacheEnable);
        return option;
    }


}
